package com.xxmw.transaction.common.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @author luowenliang
 * @since 2019-08-15 15:51
 */
public class Md5Util {

    /**
     * 国际标准
     * @param str
     * @return
     */
    public static String encoder(String str) {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(str.getBytes());
            byte[] md5Bytes = md5.digest();
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < md5Bytes.length; i++){
                int temp = md5Bytes[i] & 0xFF;
                if (temp <= 0XF) {
                    sb.append("0");
                }
                sb.append(Integer.toHexString(temp));
            }
            return sb.toString();
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalArgumentException(e);
        }
    }
}
